package com.example.quanxian2.demo1.service;

import com.example.quanxian2.demo1.VO.UserFilterVO;
import com.example.quanxian2.demo1.VO.UserInsertRoleVO;
import com.example.quanxian2.demo1.dao.UserMapper;
import com.example.quanxian2.demo1.dao.UserRoleMapper;
import com.example.quanxian2.demo1.domain.UserRoleExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserRoleMapper userRoleMapper;

    public List<UserFilterVO> selectUserResource(String resourceUrl){
        return userMapper.selectUserResource(resourceUrl);
    }

    public String insertUserRole(UserInsertRoleVO userInsertRoleVO){
        //删除当前用户的所有角色
        UserRoleExample userRoleExample = new UserRoleExample();
        UserRoleExample.Criteria criteria = userRoleExample.createCriteria();
        criteria.andUserIdEqualTo(userInsertRoleVO.getUserId());
        userRoleMapper.deleteByExample(userRoleExample);
        //添加当前用户的角色列表
        int n =userRoleMapper.insertList(userInsertRoleVO);
        if(n > 0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }

}
